import request from '@/utils/request'

export default {
  // 1.用户登录
  login ({ username, password }) {
    return request({
      url: 'login',
      method: 'post',
      params: {
        username,
        password
      }
    })
  },

  // 2.获取用户列表
  getUserList ({ query, pagenum, pagesize }) {
    return request({
      url: 'users',
      method: 'get',
      params: {
        query,
        pagenum,
        pagesize
      }
    })
  },

  // 3.更改用户状态
  updateUserState (uid, type) {
    return request({
      url: `users/${uid}/state/${type}`,
      method: 'put'
    })
  },

  // 4.添加新用户
  addUser ({ username, password, email, mobile }) {
    return request({
      url: 'users',
      method: 'post',
      data: {
        username,
        password,
        email,
        mobile
      }
    })
  },

  // 5.删除用户
  delUser (id) {
    return request({
      url: `users/${id}`,
      method: 'delete'
    })
  },

  // 6.根据id获取用户信息
  getUserInfoById (id) {
    return request({
      url: `users/${id}`,
      method: 'get'
    })
  },

  // 7.更新用户
  updateUserInfo (id, { email, mobile }) {
    return request({
      url: `users/${id}`,
      method: 'put',
      data: {
        email,
        mobile
      }
    })
  }
}
